import Vue from 'vue'
import Router from 'vue-router'

import regrster from '@/components/regrster'
import login from '@/components/login'
import Header from '@/components/http/Header'

import Home from '@/components/Home'
import Navlist from '@/components/http/Navlist'
import userlist from '@/view/user/userlist'

import one from '@/components/one'
import two from '@/components/two'
import three from '@/components/three'
Vue.use(Router)

export default new Router({
  //去掉路由#号
  mode:'history',
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home,
      beforeEnter(to,from,next){
       //是否登录，没有登录跳转到登录
       let username=localStorage.getItem('username')
       console.log(username)
       if(username){
        next()//放行
       }else{
         alert('没有登录,不能访问')
         next('/login')
       }
      },
      children:[
        {
          path: '/userlist',
          name: 'userlist',
          component: userlist
        },
        {
          path: '/navlist',
          name: 'Navlist',
          component: Navlist
        },

      ]
    },

    {
      path: '/regrster',
      name: 'regrster',
      component: regrster
    },
    {
      path: '/login',
      name: 'login',
      component: login
    },
    {
      path: '/header',
      name: 'Header',
      component: Header
    },
    
    
    
    {
      path: '/one',
      name: 'one',
      component: one,
      children:[
        {
          path: '/three',
          name: 'three',
          component: three
        }
      ]
    }
    
    
    ,{
      path: '/two',
      name: 'two',
      component: two
    } ,
   

  ]
})
